#include<bits/stdc++.h>
using namespace std;
const int N = 5e5+5;
int n,m;
int main()
{
    freopen("bishop.in","r",stdin);
    freopen("bishop.out"."w",stdout);
    ios::sync_with_stdio(false);cin.tie(0);
    cin>>n>>m;
    if(n == m)
    {
        cout<<n+m-2<<"\n";
        for(int i = 1;i <= n;i++) cout<<"1 "<<i<<"\n";
        for(int i = 2;i < n;i++) cout<<n<<" "<<i<<"\n";
        return 0;
    }
    if(n < m)
    {
        if(n & 1)
        {
            cout<<n+m-1<<"\n";
            for(int i = 1;i <= n;i++) cout<<i<<" 1\n"<<i<<" "<<m<<"\n";
            int fr = (n+1)/2+1,to = m-(n+1)/2;
            for(int i = fr;i <= to;i++) cout<<(n+1)/2<<" "<<i<<"\n";
            return 0;
        }
        m = (m-1)/2*2+1;
        cout<<n+m-1<<"\n";
        for(int i = 1;i <= n;i++) cout<<i<<" 1\n"<<i<<" "<<m<<"\n";
        int fr = n/2+2,to = m-n/2-1;
        for(int i = fr;i <= to;i+=2) cout<<n/2<<" "<<i<<"\n"<<n/2+1<<" "<<i<<"\n";
    }
    swap(n,m);
    if(n & 1)
    {
        cout<<n+m-1<<"\n";
        for(int i = 1;i <= n;i++) cout<<"1 "<<i<<"\n"<<m<<" "<<i<<"\n";
        int fr = (n+1)/2+1,to = m-(n+1)/2;
        for(int i = fr;i <= to;i++) cout<<i<<" "<<(n+1)/2<<"\n";
        return 0;
    }
    m = (m-1)/2*2+1;
    cout<<n+m-1<<"\n";
    for(int i = 1;i <= n;i++) cout<<"1 "<<i<<"\n"<<m<<" "<<i<<"\n";
    int fr = n/2+2,to = m-n/2-1;
    for(int i = fr;i <= to;i+=2) cout<<i<<" "<<n/2<<"\n"<<i<<" "<<n/2+1<<"\n";
    return 0;
}